package com.example.ui;

import com.example.huashangapp.R;
import com.example.net.Communication;
import com.example.util.Util;

import android.annotation.SuppressLint;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;

public class FindPassword1Activity extends Activity {
	private Button la_return, la_next;
	private TextView la_title;
	private EditText telEdit;
	public static Handler handler;
	public static final int FAIL = 0;
	public static final int SUCCESS = 1;
	public static final int NONE = 2;
	private String mobile="";
	@SuppressLint("HandlerLeak")
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		setContentView(R.layout.send_password);
		findView();
		handler = new Handler(){
			@Override
			public void handleMessage(Message msg) {
				// TODO Auto-generated method stub
				switch (msg.what) {
				case FAIL:
					Util.toast(FindPassword1Activity.this, "请检查您的网络");
					break;
				case SUCCESS:
					Util.toast(FindPassword1Activity.this, "密码已发送到您的手机,请注意查收");
					Intent intent = new Intent(FindPassword1Activity.this, FindPassword2Activity.class);
					intent.putExtra("mobile", telEdit.getText().toString());
					startActivity(intent);
					finish();
					break;
				case NONE:
					Util.toast(FindPassword1Activity.this, "请检查您的手机号码输入是否有误");
					break;

				default:
					break;
				}
				super.handleMessage(msg);
			}
		};
	}

	private void findView() {
		la_return = (Button) findViewById(R.id.register_return);
		la_next = (Button) findViewById(R.id.register_next);
		la_title = (TextView) findViewById(R.id.register_title);
		telEdit = (EditText)findViewById(R.id.send_password_tel);
		la_next.setText("完成");
		la_title.setText("登陆");
		la_return.setOnClickListener(la_ocl);
		la_next.setOnClickListener(new OnClickListener() {
			
			@Override
			public void onClick(View view) {
				// TODO Auto-generated method stub
				mobile = telEdit.getText().toString();
				if("".equals(mobile)){
					Util.toast(FindPassword1Activity.this, "请输入您的手机号码");
				}else{
					Communication.forgetPassword(mobile);
				}
			}
		});
		
	}
	
	private OnClickListener la_ocl=new OnClickListener() {

		@Override
		public void onClick(View v) {
			switch (v.getId()) {
			case R.id.register_return:
				finish();
				break;
//			case R.id.register_next:
//				
//				break;

			default:
				break;
			}
			
		}
		
	};

}
